// pages/shopdetails/shopdetails.js
const HTTP = require('../../utils/util');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        shop_id: '',
        goodImgList: [],
        startTime: '0:00',
        endTime: '0:00',
        address: '',
        mobile: '---',
        keywords: [],
        infoImg: [],
        status: 0,
        remarkList: [],
        shopName: '---',
        remarkCount: '--',
        eachPay: '--',
        active: 0,
        active_state: 0,
        isThumbs: 0,
        latitude: '',
        longitude: '',
        loading: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            shop_id: options.id
        });
    },
    goDrivingRoute() {
        wx.navigateTo({
            url: "../drivingroute/drivingroute?latitude=" + this.data.latitude + '&&longitude=' + this.data.longitude
        })
    },
    thumbsUp() {
        this.setData({
            loading: true
        });
        HTTP.getData('/api/shop/parise', {
            shop_id: this.data.shop_id,
        }, res => {
            this.getShopDetail(1);
        });
    },
    //支付
    goPay(e) {
        wx.navigateTo({
            url: '../pay/pay?id=' + this.data.shop_id
        });
    },
    // 获取商店详细
    getShopDetail(e) {
        HTTP.getData('/api/shop/detail', {
            shop_id: this.data.shop_id,
            type: e,
            status: this.data.status
        }, res => {
            this.setData({
                goodImgList: res.data.good_pic,
                startTime: res.data.start_time,
                endTime: res.data.end_time,
                address: res.data.address,
                mobile: res.data.mobile,
                keywords: res.data.keywords,
                infoImg: res.data['info'],
                remarkList: res.data['evaluate'],
                shopName: res.data.name,
                remarkCount: res.data.evaluate_count,
                eachPay: res.data.conume,
                cate: res.data.cate_name,
                isThumbs: +res.data.is_parise,
                latitude: +res.data.latitude,
                longitude: res.data.longitude,
                loading: false
            })
        });
    },
    //进入评论
    goRemark(e) {
        this.setData({
            active: 1,
            status: 0
        })
    },
    // openMap() {
    //     wx.getLocation({
    //         type: 'gcj02', //返回可以用于wx.openLocation的经纬度
    //         success(res) {
    //             console.log(res);
    //             const latitude = res.latitude
    //             const longitude = res.longitude
    //             wx.openLocation({
    //                 latitude,
    //                 longitude,
    //                 scale: 18
    //             })
    //         }
    //     })
    // },
    openMap() {
        const latitude = +this.data.latitude
        const longitude = +this.data.longitude
        wx.openLocation({
            latitude,
            longitude,
            scale: 18
        })
    },
    // 点击筛选评论
    changeState(e) {
        this.setData({
            status: Number(e.target.dataset.id)
        });
        this.getShopDetail(2)
    },
    // 监听tab切换
    onTabChange(e) {
        if (e.detail.index === 0) {
            ;
            this.getShopDetail(1)
            this.setData({
                active: 0,
                status: 0
            })
        } else if (e.detail.index === 1) {
            this.getShopDetail(2);
            this.setData({
                status: 0,
                active: 1
            })
        }
    },
    //打电话
    phoneCall() {
        wx.makePhoneCall({
            phoneNumber: this.data.mobile//仅为示例，并非真实的电话号码
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getShopDetail(1);
    },

    onClick(e) {
        this.setData({
            active: e.detail.index
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})